#!/home/guochang/anaconda3/bin/python3.7
import numpy as np
import matplotlib.pyplot as plt
filelist = ['cfl_0.25', 'cfl_0.5', 'cfl_0.75', 'cfl_1.0']
# filename = input('File name:\n>>>')
for fc in range(0, len(filelist)):
    filename = filelist[fc]
    outname = './'+filename+'.eps'
    with open(filename+'.bin', 'rb') as f:
        tem = np.fromfile(f, dtype='i4', count=1)
        nx = tem[0]
        tem = np.fromfile(f, dtype='i4', count=1)
        ntend = tem[0]
        x = [0 for i in range(0, nx)]
        for i in range(0, nx):
            tem = np.fromfile(f, dtype='float32', count=1)
            x[i] = tem[0]

        t = np.zeros([1, ntend+1])
        u = np.zeros([ntend+1, nx])
        for i in range(0, ntend+1):
            tem = np.fromfile(f, dtype='f4', count=1)
            t[0][i] = tem[0]
            for j in range(0, nx):
                tem = np.fromfile(f, dtype='f4', count=1)
                u[i][j] = tem[0]

        plt.figure(1, (20, 10))
    for k in range(0, ntend+1):
        name = 't={0:5.2f}'.format(t[0][k])
        plt.plot(x, u[k, :], label=name, linewidth=2.0)
    plt.legend(prop={'size': 22})
    plt.tick_params(which='both', labelsize=20, width=4.0)
    fig = plt.gcf()
    ax = plt.gca()
    fig.savefig(outname, format='eps', dpi=1000)
    plt.show()
    # plt.savefig('./result.png')
    f.close()
